﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Supermarket;

namespace XLSupermarket.Admin.Ad_zscg
{
    public partial class Ad_zscg : Form
    {
        public Ad_zscg()
        {
            InitializeComponent();
        }
        //定义一个能够让其他窗体调用的对象
        public static string ID;


        private void Ad_zscg_Load(object sender, EventArgs e)
        {
            try { 
            string sql = "select*from VIP_information";
            DataTable sc = DBHelper.FillData(sql);
            this.dataGridView1.DataSource = sc;
            this.dataGridView1.AutoGenerateColumns = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try { 
            string stuname = this.textBox1.Text;
            string sql = string.Format("select*from VIP_information where VIP_Name like '%{0}%'", stuname);
            //调用方法
            DataTable sc = DBHelper.FillData(sql);
            this.dataGridView1.DataSource = sc;
            //取消自增列
            this.dataGridView1.AutoGenerateColumns = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }

        private void 添加会员信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cashier.VIP.Add_VIP CVA = new Cashier.VIP.Add_VIP();
            CVA.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try { 
            //绑定dataGridView1的信息到文本框中
             ID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int num = dataGridView1.SelectedRows.Count;
            if (num <= 0)
            {
                MessageBox.Show("您没有选中行！");
                return;
            }
            Admin.Ad_update.Ad_update AAAu = new Admin.Ad_update.Ad_update();
            AAAu.ShowDialog();//绑定dataGridView1的信息到文本框中
            //刷新dataGridView中修改的信息
            string sqll = "select*from VIP_information";
            DataTable sc = DBHelper.FillData(sqll);
            this.dataGridView1.DataSource = sc;
            this.dataGridView1.AutoGenerateColumns = false;
            ID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            MessageBox.Show(ID);
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
    }
}
